package org.TheSubject;

import java.util.ArrayList;
import java.util.List;

public class Solution17OfHot {
   public static List<String[]> strings;
   static {
       strings=new ArrayList<>(11);
        strings.add(null);
        strings.add(null);
        strings.add(new String[]{"a","b","c"});
       strings.add(new String[]{"d","e","f"});
       strings.add(new String[]{"g","h","i"});
       strings.add(new String[]{"j","k","l"});
       strings.add(new String[]{"m","n","o"});
       strings.add(new String[]{"p","q","r","s"});
       strings.add(new String[]{"t","u","v"});
       strings.add(new String[]{"w","x","y","z"});
   }

    public List<String> letterCombinations(String digits) {
        result =new ArrayList<>();
        int length = digits.length();
        if (length==0){
            return result;
        }
        this.digits=digits;
        this.resultBuilder=new StringBuilder(length);
        backToFind(0);
        return result;
    }
    private List<String> result;
    private StringBuilder resultBuilder;
    private String digits;
    public void backToFind(int index){
        if (index>=digits.length()){
            result.add(resultBuilder.toString());
        }else {
            Integer integer = digits.charAt(index)-'0';
            String[] strings = Solution17OfHot.strings.get(integer);
            for (String s:strings){
                resultBuilder.append(s);
                backToFind(index+1);
                resultBuilder.deleteCharAt(resultBuilder.length()-1);
            }

        }
    }

}
